package com.panwenliang2008.eatwhat.ui.copyright

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.panwenliang2008.eatwhat.R
import com.panwenliang2008.eatwhat.utilities.COPYRIGHT_FILENAME
import kotlinx.android.synthetic.main.copyright_fragment.*


class CopyrightFragment : Fragment() {

    companion object {
        fun newInstance() = CopyrightFragment()
    }

    private lateinit var viewModel: CopyrightViewModel

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.copyright_fragment, container, false)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProvider(this).get(CopyrightViewModel::class.java)

        requireActivity().applicationContext.assets.open(COPYRIGHT_FILENAME).use { inputStream ->
            inputStream.bufferedReader().use {
                textCopyright.text = it.readText()
                textCopyright.movementMethod = ScrollingMovementMethod()
            }
        }
    }

}
